﻿//************************************************************************************************************
// CoNatural.Data.dll
// Author: Roger Torres
//************************************************************************************************************
// You can use, modify, and distribute the source code and executable programs based on the source code.
// This source code is provided "as is" and without warranties as to performance or merchantability. 
// The author and/or distributors of this source code may have made statements about this source code. 
// Any such statements do not constitute warranties and shall not be relied on by the user in deciding 
// whether to use this source code. This source code is provided without any express or implied warranties 
// whatsoever. Because of the diversity of conditions and hardware under which this source code may be used, 
// no warranty of fitness for a particular purpose is offered. The user is advised to test the source code 
// thoroughly before relying on it. The user must assume the entire risk of using the source code.
//************************************************************************************************************

using System;
using System.Data;
using System.Reflection;

namespace CoNatural.Data {
	/// <summary>
	/// Attribute to annotate command properties mapped to sql parameters.
	/// </summary>
	[AttributeUsage(AttributeTargets.Property)]
	public class ParameterAttribute : Attribute {
		internal ParameterDirection Direction = ParameterDirection.Input;
		internal int Size = -1; // for varchar(MAX), varbinary(MAX)
		internal byte Precision = 0;
		internal byte Scale = 0;
		internal bool IsNullableString = false; // cannot use string? because strings are nullable by default

		/// <summary>
		/// Creates a new parameter attribute
		/// </summary>
		public ParameterAttribute() {}

		/// <summary>
		/// Creates a new parameter attribute
		/// </summary>
		/// <param name="direction">The direction of the parameter.</param>
		public ParameterAttribute(ParameterDirection direction) {
			this.Direction = direction;
		}

		/// <summary>
		/// Creates a new input string or binary parameter attribute.
		/// </summary>
		/// <param name="size">The size of the parameter. Use with string types.</param>
		public ParameterAttribute(int size) {
			this.Size = size;
		}

		/// <summary>
		/// Creates a new input string parameter attribute.
		/// </summary>
		/// <param name="size">The size of the parameter. Use with string types.</param>
		/// <param name="isNullableString">True to flag a nullable string.</param>
		public ParameterAttribute(int size, bool isNullableString) {
			this.Size = size;
			this.IsNullableString = isNullableString; 
		}

		/// <summary>
		/// Creates a new input decimal parameter attribute. 
		/// </summary>
		/// <param name="precision">The precision of the parameter. Used with decimal types.</param>
		/// <param name="scale">The scale of the parameter. Used with decimal types.</param>
		public ParameterAttribute(byte precision, byte scale) {
			this.Precision = precision;
			this.Scale = scale;
		}

		/// <summary>
		/// Creates a new string or binary parameter attribute. 
		/// </summary>
		/// <param name="direction">The direction of the parameter.</param>
		/// <param name="size">The size of the parameter. Used with string types.</param>
		public ParameterAttribute(ParameterDirection direction, int size) {
			this.Direction = direction;
			this.Size = size;
		}

		/// <summary>
		/// Creates a new string parameter attribute. 
		/// </summary>
		/// <param name="direction">The direction of the parameter.</param>
		/// <param name="size">The size of the parameter. Used with string types.</param>
		/// <param name="isNullableString">True to flag a nullable string.</param>
		public ParameterAttribute(ParameterDirection direction, int size, bool isNullableString) {
			this.Direction = direction;
			this.Size = size;
			this.IsNullableString = isNullableString;
		}

		/// <summary>
		/// Creates a new decimal parameter attribute. 
		/// </summary>
		/// <param name="direction">The direction of the parameter.</param>
		/// <param name="precision">The precision of the parameter. Used with decimal types.</param>
		/// <param name="scale">The scale of the parameter. Used with decimal types.</param>
		public ParameterAttribute(ParameterDirection direction, byte precision, byte scale) {
			this.Direction = direction;
			this.Precision = precision;
			this.Scale = scale;
		}
	}
}
